package org.dydl.controller.system;

import org.dydl.common.dto.ResponseMessage;
import org.dydl.model.system.Goods;
import org.dydl.service.system.IMaterialRepertoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/materialRepertory")
public class MaterialRepertoryController {

	@Autowired
	private IMaterialRepertoryService materialRepertoryService;

	/**
	 * 增加原材料库存
	 */
	@RequestMapping("/save")
	public ResponseMessage save(@RequestBody Goods goods){

		goods.setPn(goods.getSku());
		ResponseMessage res = materialRepertoryService.save(goods);
		return res;
	}

	/**
	 * 更新原材料库存
	 */
	@RequestMapping("/update")
	public ResponseMessage update(@RequestBody Goods goods){
		goods.setPn(goods.getSku());

		ResponseMessage res = materialRepertoryService.save(goods);
		return res;
	}

	/**
	 * 查询原材料库存
	 */
	@RequestMapping("/list")
	public ResponseMessage getMaterialRepertoryList(int page, int rows, String name){
		ResponseMessage goodsList = materialRepertoryService.getMaterialRepertoryList(page, rows, name);
		return goodsList;
	}

	/**
	 * 删除原材料库存
	 */
	@RequestMapping("/delete")
	public boolean delete(int[] ids){
		if (ids.length != 0) {
			for (int i = 0; i < ids.length; i++) {
				materialRepertoryService.delete(ids[i]);
			}
			return true;
		} else {
			return false;
		}

	}
}
